<?xml version="1.0" encoding="UTF-8"?>
<!--

       Copyright 2006-2021 the original author or authors.

       Licensed under the Apache License, Version 2.0 (the "License");
       you may not use this file except in compliance with the License.
       You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

       Unless required by applicable law or agreed to in writing, software
       distributed under the License is distributed on an "AS IS" BASIS,
       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       See the License for the specific language governing permissions and
       limitations under the License.

-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>The &lt;javaClientGenerator&gt; Element</title>
  <link rel="stylesheet" type="text/css" href="../mbgstyle.css" />
</head>
<body>
<h1>The &lt;javaClientGenerator&gt; Element</h1>
<p>The &lt;javaClientGenerator&gt; element is used to define properties of the Java
client generator.  The Java client Generator builds Java interfaces and classes that allow
easy use of the generated Java model and XML map files. For MyBatis, the
generated objects take the form of mapper interfaces.
This element is a optional child element
of the <a href="context.html">&lt;context&gt;</a> element.  If you do not
specify this element, then MyBatis Generator (MBG) will not generate Java client interfaces and classes.</p>
<h2>Required Attributes</h2>
<table border="1" cellspacing="0" cellpadding="5">
  <tr>
    <th>Attribute</th>
    <th>Description</th>
  </tr>
  <tr>
    <td valign="top">type</td>
    <td>This attribute is used to select one of the predefined Java Client generators, or
        to specify a user provided Java Client generator.
        Any user provided generator must extend the class
        <code>org.mybatis.generator.codegen.AbstractJavaClientGenerator</code>
        class, and must have a public default constructor.
        <p>The attribute accepts the following values for selecting one of the
        predefined generators:</p>
        <table cellpadding="5">
          <tr>
            <td colspan="2">If the &lt;context&gt; targetRuntime is <b>MyBatis3DynamicSql</b> this attribute is optional and ignored.</td>
          </tr>
          <tr>
            <td colspan="2">If the &lt;context&gt; targetRuntime is <b>MyBatis3Kotlin</b> this attribute is optional and ignored.</td>
          </tr>
          <tr>
            <td colspan="2">If the &lt;context&gt; targetRuntime is <b>MyBatis3</b> the following predefined values can be used:</td>
          </tr>
          <tr>
            <th nowrap="nowrap" valign="top">ANNOTATEDMAPPER</th>
            <td>The generated objects will be Java interfaces for the MyBatis 3.x mapper
            infrastructure.  The interfaces will be based on annotations and MyBatis 3.x SqlProviders.
            No XML mapper files will be generated.
            <p>The ANNOTATEDMAPPER requires MyBatis version 3.0.4 or higher.</p>
            </td>
          </tr>
          <tr>
            <th nowrap="nowrap" valign="top">MIXEDMAPPER</th>
            <td>The generated objects will be Java interfaces for the MyBatis 3.x mapper
            infrastructure.  The interfaces will be based on a mix of annotations and XML.
            An annotation will be used where a simple annotation will work.  This client
            will not generate and Sql Provider, so all complex dynamic SQL will be generated
            in XML.
            <p>The MIXEDMAPPER requires MyBatis version 3.0.4 or higher.</p>
            </td>
          </tr>
          <tr>
            <th nowrap="nowrap" valign="top">XMLMAPPER</th>
            <td>The generated objects will be Java interfaces for the MyBatis 3.x mapper
            infrastructure.  The interfaces will be dependent on generated XML mapper files.</td>
          </tr>
          <tr>
            <td colspan="2">If the &lt;context&gt; targetRuntime is <b>MyBatis3Simple</b> the following predefined values can be used:</td>
          </tr>
          <tr>
            <th nowrap="nowrap" valign="top">ANNOTATEDMAPPER</th>
            <td>The generated objects will be Java interfaces for the MyBatis 3.x mapper
            infrastructure.  The interfaces will be based on annotations and MyBatis 3.x SqlProviders.
            No XML mapper files will be generated.
            <p>The ANNOTATEDMAPPER requires MyBatis version 3.0.4 or higher.</p>
            </td>
          </tr>
          <tr>
            <th nowrap="nowrap" valign="top">XMLMAPPER</th>
            <td>The generated objects will be Java interfaces for the MyBatis 3.x mapper
            infrastructure.  The interfaces will be dependent on generated XML mapper files.</td>
          </tr>
        </table>
    </td>
  </tr>
  <tr>
    <td valign="top">targetPackage</td>
    <td>This is the package where the generated interfaces and implementation classes
        will be placed.  In
        the default generators, the property "enableSubPackages"
        controls how the actual package is calculated.  If true,
        then the calculated package will be the targetPackage plus
        sub packages for the table's catalog and schema if they exist.
        If "enableSubPackages" is false (the default) then the calculated package will be
        exactly what is specified in the targetPackage attribute.
        MBG will create folders as required for the generated
        packages.</td>
  </tr>
  <tr>
    <td valign="top">targetProject</td>
    <td>This is used to specify a target project for the
        generated interfaces and classes.  When running in the Eclipse
        environment, this specifies the project and source folder where
        the objects will be saved.
        In other environments, this value should be an existing directory
        on the local file system.  MBG will not create this directory if
        it does not exist.</td>
  </tr>
</table>

<h2>Child Elements</h2>
<ul>
  <li><a href="property.html">&lt;property&gt;</a> (0..N)</li>
</ul>

<h2>Supported Properties</h2>
<p>This table lists the properties of the default SQL Map generators that can be
specified with the <a href="property.html">&lt;property&gt;</a> child element:</p>
<table border="1" cellspacing="0" cellpadding="5">
  <tr>
    <th>Property Name</th>
    <th>Property Values</th>
  </tr>
  <tr>
      <td valign="top">dynamicSqlSupportPackage</td>
      <td>This property is only applicable to target runtimes <b>MyBatis3DynamicSql</b> or <b>MyBatis3Kotlin</b>.
          Use this property to set the package where generated MyBatis Dynamic SQL Support classes will be placed.
          The calculated package can be modified by the "enableSubPackages" property in the same way as the
          "targetPackage".
          If not specified, the package will be the same as "targetPackage" specified above.
          <p>Since version 1.4.1</p>
      </td>
  </tr>
  <tr>
    <td valign="top">enableSubPackages</td>
    <td>This property is used to select whether MBG will generate different
        Java packages for the objects based on the catalog and schema of the
        introspected table.
        <p>For example, suppose a table MYTABLE in schema MYSCHMA.
        Also suppose that the targetPackage attribute is set to "com.mycompany".
        If this property is true, the generated DAO interface and class for the table
        will be placed in
        the package "com.mycompany.myschema".  If the property is false, the generated
        SQL Map will be placed in the "com.mycompany" schema.</p>
        <p><i>The default value is false.</i></p></td>
  </tr>
  <tr>
    <td valign="top">rootInterface</td>
    <td><i>This property is ignored if the target runtime is "MyBatis3Kotlin"</i><br/>
        This property can be used to specify a super interface for all generated
      interface objects.  This value may be overridden by specifying
      the <code>rootInterface</code> property on a Table configuration.
      <p><b>Important:</b> MBG does not verify that the interface exists, or is a
       valid Java interface.</p>
      <p>If specified, the value of this property should be a fully qualified
       interface name (like com.mycompany.MyRootInterface).</p></td>
  </tr>
</table>

<h2>Example</h2>
<p>This element specifies that we always want to place generated interfaces and
objects
in the "'test.model" package and that we want to use subpackages based on the
table schema and catalog.  It also specifies that we want to generate
mapper interfaces that reference an XML configuration file for MyBatis3.</p>
<pre>
&lt;javaClientGenerator targetPackage="test.model"
     targetProject="\MyProject\src" type="XMLMAPPER"&gt;
  &lt;property name="enableSubPackages" value="true" /&gt;
&lt;/javaClientGenerator&gt;
</pre>

</body>
</html>
